package com.aiju.widgit.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiju.base.R;
import com.aiju.base.dialog.BaseDialog;
import com.aiju.common.PixValue;

/**
 * @author: 佐为
 * @date: 2016-11-17 14:52
 * @version: V1.0
 * @Description: 版本升级提示
 */
public class VersionDialog extends BaseDialog implements View.OnClickListener {

    private TextView titleTextView;
    private TextView updateTextView;
    private ImageView deleteTextView;

    public VersionDialog(Context context) {
        super(context);
    }

    @Override
    protected int getDialogStyleId() {
        return R.style.dialog;
    }

    @Override
    protected View getView() {
        View inflate = mLayoutInflater.inflate(R.layout.dialog_version, null);
        titleTextView = (TextView) inflate.findViewById(R.id.tv_version_detail);
        updateTextView = (TextView) inflate.findViewById(R.id.tv_version_update);
        deleteTextView = (ImageView) inflate.findViewById(R.id.iv_version_delete);
        updateTextView.setOnClickListener(this);
        deleteTextView.setOnClickListener(this);
        return inflate;
    }

    /**
     * 设置对话框LayoutParams
     *
     * @return
     */
    public VersionDialog setLayoutParams() {
        WindowManager.LayoutParams lp = getDialogWindow().getAttributes();
        lp.width = PixValue.dp.valueOf(253);
        lp.height = PixValue.dp.valueOf(414);
        getDialogWindow().setGravity(Gravity.CENTER);
        getDialogWindow().setAttributes(lp);
        return this;
    }

    public VersionDialog setTitileText(String titile) {
        this.titleTextView.setText(titile);
        return this;
    }

    public VersionDialog setLeftText(String leftText) {
        this.updateTextView.setText(leftText);
        return this;
    }

    private OnSimpleClick mOnSimpleClick;

    public VersionDialog setOnSimpleClick(OnSimpleClick onSimpleClick) {
        this.mOnSimpleClick = onSimpleClick;
        return this;
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.iv_version_delete) {
            if (mOnSimpleClick != null) {
                mOnSimpleClick.onCancel();
                dismiss();
            }
        } else if (i == R.id.tv_version_update) {
            if (mOnSimpleClick != null) {
                mOnSimpleClick.onSubmit();
                dismiss();
            }
        }
    }

    public interface OnSimpleClick {
        void onCancel();

        void onSubmit();
    }


}
